{"ast":null,"code":"import { createTrackingData } from \"./reactionCleanupTrackingCommon\";\n/**\n * FinalizationRegistry-based uncommitted reaction cleanup\n */\nexport function createReactionCleanupTrackingUsingFinalizationRegister(FinalizationRegistry) {\n  var cleanupTokenToReactionTrackingMap = new Map();\n  var globalCleanupTokensCounter = 1;\n  var registry = new FinalizationRegistry(function cleanupFunction(token) {\n    var trackedReaction = cleanupTokenToReactionTrackingMap.get(token);\n    if (trackedReaction) {\n      trackedReaction.reaction.dispose();\n      cleanupTokenToReactionTrackingMap.delete(token);\n    }\n  });\n  return {\n    addReactionToTrack: function (reactionTrackingRef, reaction, objectRetainedByReact) {\n      var token = globalCleanupTokensCounter++;\n      registry.register(objectRetainedByReact, token, reactionTrackingRef);\n      reactionTrackingRef.current = createTrackingData(reaction);\n      reactionTrackingRef.current.finalizationRegistryCleanupToken = token;\n      cleanupTokenToReactionTrackingMap.set(token, reactionTrackingRef.current);\n      return reactionTrackingRef.current;\n    },\n    recordReactionAsCommitted: function (reactionRef) {\n      registry.unregister(reactionRef);\n      if (reactionRef.current && reactionRef.current.finalizationRegistryCleanupToken) {\n        cleanupTokenToReactionTrackingMap.delete(reactionRef.current.finalizationRegistryCleanupToken);\n      }\n    },\n    forceCleanupTimerToRunNowForTests: function () {\n      // When FinalizationRegistry in use, this this is no-op\n    },\n    resetCleanupScheduleForTests: function () {\n      // When FinalizationRegistry in use, this this is no-op\n    }\n  };\n}","map":{"version":3,"mappings":"AAEA,SAGIA,kBAAkB,QACf,iCAAiC;AAExC;;;AAGA,OAAM,SAAUC,sDAAsD,CAClEC,oBAA4E;EAE5E,IAAMC,iCAAiC,GAAG,IAAIC,GAAG,EAA6B;EAC9E,IAAIC,0BAA0B,GAAG,CAAC;EAElC,IAAMC,QAAQ,GAAG,IAAIJ,oBAAoB,CAAC,SAASK,eAAe,CAACC,KAAa;IAC5E,IAAMC,eAAe,GAAGN,iCAAiC,CAACO,GAAG,CAACF,KAAK,CAAC;IACpE,IAAIC,eAAe,EAAE;MACjBA,eAAe,CAACE,QAAQ,CAACC,OAAO,EAAE;MAClCT,iCAAiC,CAACU,MAAM,CAACL,KAAK,CAAC;;EAEvD,CAAC,CAAC;EAEF,OAAO;IACHM,kBAAkB,EAAlB,UACIC,mBAAqE,EACrEJ,QAAkB,EAClBK,qBAA6B;MAE7B,IAAMR,KAAK,GAAGH,0BAA0B,EAAE;MAE1CC,QAAQ,CAACW,QAAQ,CAACD,qBAAqB,EAAER,KAAK,EAAEO,mBAAmB,CAAC;MACpEA,mBAAmB,CAACG,OAAO,GAAGlB,kBAAkB,CAACW,QAAQ,CAAC;MAC1DI,mBAAmB,CAACG,OAAO,CAACC,gCAAgC,GAAGX,KAAK;MACpEL,iCAAiC,CAACiB,GAAG,CAACZ,KAAK,EAAEO,mBAAmB,CAACG,OAAO,CAAC;MAEzE,OAAOH,mBAAmB,CAACG,OAAO;IACtC,CAAC;IACDG,yBAAyB,EAAzB,UAA0BC,WAA6D;MACnFhB,QAAQ,CAACiB,UAAU,CAACD,WAAW,CAAC;MAEhC,IAAIA,WAAW,CAACJ,OAAO,IAAII,WAAW,CAACJ,OAAO,CAACC,gCAAgC,EAAE;QAC7EhB,iCAAiC,CAACU,MAAM,CACpCS,WAAW,CAACJ,OAAO,CAACC,gCAAgC,CACvD;;IAET,CAAC;IACDK,iCAAiC;MAC7B;IACJ,CAAC;IACDC,4BAA4B;MACxB;IACJ;GACH;AACL","names":["createTrackingData","createReactionCleanupTrackingUsingFinalizationRegister","FinalizationRegistry","cleanupTokenToReactionTrackingMap","Map","globalCleanupTokensCounter","registry","cleanupFunction","token","trackedReaction","get","reaction","dispose","delete","addReactionToTrack","reactionTrackingRef","objectRetainedByReact","register","current","finalizationRegistryCleanupToken","set","recordReactionAsCommitted","reactionRef","unregister","forceCleanupTimerToRunNowForTests","resetCleanupScheduleForTests"],"sources":["/data/messenger.client/node_modules/mobx-react-lite/src/utils/createReactionCleanupTrackingUsingFinalizationRegister.ts"],"sourcesContent":["import { FinalizationRegistry as FinalizationRegistryMaybeUndefined } from \"./FinalizationRegistryWrapper\"\nimport { Reaction } from \"mobx\"\nimport {\n    ReactionCleanupTracking,\n    IReactionTracking,\n    createTrackingData\n} from \"./reactionCleanupTrackingCommon\"\n\n/**\n * FinalizationRegistry-based uncommitted reaction cleanup\n */\nexport function createReactionCleanupTrackingUsingFinalizationRegister(\n    FinalizationRegistry: NonNullable<typeof FinalizationRegistryMaybeUndefined>\n): ReactionCleanupTracking {\n    const cleanupTokenToReactionTrackingMap = new Map<number, IReactionTracking>()\n    let globalCleanupTokensCounter = 1\n\n    const registry = new FinalizationRegistry(function cleanupFunction(token: number) {\n        const trackedReaction = cleanupTokenToReactionTrackingMap.get(token)\n        if (trackedReaction) {\n            trackedReaction.reaction.dispose()\n            cleanupTokenToReactionTrackingMap.delete(token)\n        }\n    })\n\n    return {\n        addReactionToTrack(\n            reactionTrackingRef: React.MutableRefObject<IReactionTracking | null>,\n            reaction: Reaction,\n            objectRetainedByReact: object\n        ) {\n            const token = globalCleanupTokensCounter++\n\n            registry.register(objectRetainedByReact, token, reactionTrackingRef)\n            reactionTrackingRef.current = createTrackingData(reaction)\n            reactionTrackingRef.current.finalizationRegistryCleanupToken = token\n            cleanupTokenToReactionTrackingMap.set(token, reactionTrackingRef.current)\n\n            return reactionTrackingRef.current\n        },\n        recordReactionAsCommitted(reactionRef: React.MutableRefObject<IReactionTracking | null>) {\n            registry.unregister(reactionRef)\n\n            if (reactionRef.current && reactionRef.current.finalizationRegistryCleanupToken) {\n                cleanupTokenToReactionTrackingMap.delete(\n                    reactionRef.current.finalizationRegistryCleanupToken\n                )\n            }\n        },\n        forceCleanupTimerToRunNowForTests() {\n            // When FinalizationRegistry in use, this this is no-op\n        },\n        resetCleanupScheduleForTests() {\n            // When FinalizationRegistry in use, this this is no-op\n        }\n    }\n}\n"]},"metadata":{},"sourceType":"module"}